<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>优惠券管理</title>
    <link rel="shortcut icon" href="favicon.ico"> <link href="__PUBLIC__/Theme1/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/Theme1/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/Theme1/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="__PUBLIC__/Theme1/css/animate.min.css" rel="stylesheet">
    <link href="__PUBLIC__/Theme1/css/style.min.css?v=4.1.0" rel="stylesheet">
    <script language="javascript" type="text/javascript" src="__PUBLIC__/My97DatePicker/WdatePicker.js"></script>

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑优惠券<small></small></h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form method="post" action="__URL__/save" class="form-horizontal" onsubmit="return my_check();" enctype="multipart/form-data">

                        <input type="hidden" value="{$result.coupon_id}" name="coupon_id">

                        <if condition="$storeId eq 0">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">店铺名称</label>
                                <div class="col-sm-4">
                                    <select id="category2" class="form-control" required name="store_id">
                                        <option value="0" >请选择..</option>
                                        <volist name="store" id="vo">
                                            <option value="{$vo['store_id']}" <if condition="$result['store_id'] eq $vo['store_id']"> selected </if>>{$vo['store_name']}</option>
                                        </volist>
                                    </select>
                                </div>
                            </div>
                        </if>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">优惠券名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="name" id="name" placeholder="请输入优惠券名称" value="{$result.name}" required >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">发放类型</label>
                            <div class="col-sm-10">
                                <input type="radio" name="type" <if condition="$result['type'] eq 1"> checked </if> value="1">进店领取
                                <input type="radio" name="type" <if condition="$result['type'] eq 2"> checked </if> value="2">评价赠送
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">优惠券金额</label>
                            <div class="col-sm-10">
                                <input type="tel" name="money" id="money" placeholder="优惠券金额" value="{$result.money}" class="form-control" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">优惠券条件金额</label>
                            <div class="col-sm-10">
                                <input type="text" name="condition_money" id="condition_money" placeholder="优惠券条件金额" value="{$result.condition_money}" class="form-control" required>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">有效期开始时间</label>
                            <div class="col-sm-10">
                                <input type="text" name="use_start_time" id="countTimestart" onfocus="selecttime(1)" value="{$result.use_start_time}" size="17" class="date" readonly>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">有效期结束时间</label>
                            <div class="col-sm-10">
                                <input type="text" name="use_end_time" id="countTimeend" onfocus="selecttime(2)" value="{$result.use_end_time}" size="17"  class="date" readonly>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" type="submit">保存</button>
                                <a class="btn btn-white" href="{:U('Admin/Coupon/index')}">返回</a>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="__PUBLIC__/Theme1/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/Theme1/js/bootstrap.min.js?v=3.3.6"></script>
<script src="__PUBLIC__/Theme1/js/content.min.js?v=1.0.0"></script>
<script src="__PUBLIC__/Theme1/js/plugins/iCheck/icheck.min.js"></script>
<script>
    $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});

    function selecttime(flag){
        if(flag==1){
            var endTime = $("#countTimeend").val();
            if(endTime != ""){
                WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:endTime});
            }else{
                WdatePicker({dateFmt:'yyyy-MM-dd'});
            }
        }else{
            var startTime = $("#countTimestart").val();
            if(startTime != ""){
                WdatePicker({dateFmt:'yyyy-MM-dd',minDate:startTime});
            }else{
                WdatePicker({dateFmt:'yyyy-MM-dd'});
            }
        }
    }

    //满减条件价格大于满减价格
    function my_check(){
        var name=$("#name").val();
        var condition_money =  $("#condition_price").val();
        var money =  $("#money").val();

        if(name==""){
            alert("优惠券名称不能为空")
            return false;
        }

        if(condition_price==""){
            alert("条件金额不能为空")
            return false;
        }

        if(money==""){
            alert("优惠券金额不能为空")
            return false;
        }

        if(parseInt(money) > parseInt(condition_money)){
            alert("优惠券金额要小于条件金额")
            return false;
        }

        var countTimestart = $("#countTimestart").val();
        if(countTimestart==""){
            alert("开始时间不能为空")
            return false;
        }

        var countTimeend = $("#countTimeend").val();
        if(countTimeend==""){
            alert("结束时间不能为空")
            return false;
        }
    }

</script>
</body>

</html>
